import { defineStore } from 'pinia'

const useStore = defineStore('store', {
  state: () => ({
    count: 1
  }),
  actions: {
    add() {
      this.count++
    }
  },
  getters: {
    doubleCount: (state) => state.count * 2,
    multipleCount: (state) => {
      return (multiple = 1) => state.count * multiple
    }
  },
  persist: {
    enabled: false, //开启持久化
    strategies: [
      {
        key: 'store', // key store标识
        storage: localStorage, // 仓库类型
        paths: ['count'] //state 中的变量 不传全存
      }
    ]
  }
})

export default useStore
